<template>
    <div v-for="item in list" :ref="setItemRef">{{ item }}</div>
    <button @click="changeRefs">改变</button>
</template>

<script setup lang="ts">
    import { ref, onBeforeUpdate, onUpdated } from 'vue'

    const list = ref<number[]>([1, 2, 3, 4])
    let itemRefs: any[] = []

    const setItemRef = (el: any) => {
        if (el) {
            itemRefs.push(el)
        }
    }
    const changeRefs = () => {
        list.value.push(list.value.length + 1)
    }
    onBeforeUpdate(() => {
        itemRefs = []
    })
    onUpdated(() => {
        console.log('itemRefs :>> ', itemRefs)
    })
</script>
<style lang="scss" scoped></style>
